import request from "@/service/request";
import { PromisePageResponse, PromiseResponse } from "@/service/api/type.ts";
import {
  SysUserVo,
  SysUserInfoVo,
  RegionOrganizationMixedVo,
} from "./types";

/**
 * 获取用户列表
 * @param query
 */
const getUserList = (query: any): PromisePageResponse<SysUserVo> => {
  return request({
    url: "/system/user/list",
    method: "get",
    params: query,
  });
};

/**
 * 获取用户可见的区域组织树
 * @param userId
 */
const getRegionOrganizationTree = (userId: string): PromiseResponse<RegionOrganizationMixedVo> => {
  return request({
    url: `/system/organization/mixedTreeselect/${userId}`,
    method: "get",
  });
};

/**
 * 保存区域组织
 * @param query
 */
const saveRegionOrganization = (query: any): PromiseResponse<any> => {
  return request({
    url: "/system/user/dataScope",
    method: "put",
    data: query
  });
};

/**
 * 获取用户详情
 * @param userId
 */
const getUserDetail = (userId: string): PromiseResponse<SysUserInfoVo> => {
  return request({
    url: `/system/user/${userId}`,
    method: "get",
  });
};

export {
  getUserList,
  getRegionOrganizationTree,
  saveRegionOrganization,
  getUserDetail,
};
